package com.itheima.controller;

import com.itheima.entity.StatusCode;
import com.itheima.pojo.SysDictData;
import com.itheima.service.SysDictDataService;
import com.itheima.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/sysDictData")
@CrossOrigin
public class SysDictDataController {

    @Autowired
    private SysDictDataService sysDictDataService;
    private ResultUtil resultUtil;

    /**
     * 根据字典类型获取字典数据
     *@param dictType
     * @return com.itheima.entity.Result
     *@author itheima
     */
    @PostMapping("/getListByType")
    public String getListByType(@RequestParam String dictType) {
        List<SysDictData> sysDictDataList = sysDictDataService.getListByDictType(dictType);
        return ResultUtil.result(StatusCode.OK,sysDictDataList);
    }

    /**
     * 根据字典类型数组获取字典数据
     *@param dictTypeList
     * @return java.lang.String
     *@author itheima
     */
    @PostMapping("/getListByDictTypeList")
    public String getListByDictTypeList(@RequestBody List<String> dictTypeList) {
        List<SysDictData> dictTypeLists = sysDictDataService.getListByDictTypeList(dictTypeList);
        return ResultUtil.result(HttpServletResponse.SC_OK,dictTypeLists);
    }

}
